<table id="tb_ql" width="805" border="1">
    <tr class="nodrop nodrag">
        <th>问题ID</th>
        <th>title</th>
        <th>反馈结果</th>
    </tr>
    <?php
    if ($reader_survey != null) {

    $survey_feedbacks = $reader_survey->getReaderSurveyFeedback();
    $report_data = array();
    foreach ($survey_feedbacks as $feedback) {
        $details = $feedback->getReaderSurveyFeedbackDetail();
        foreach ($details as $detail) {
            $qid = $detail->getQuestionId();
            $q = $detail->getReaderSurveyQuestion();
            if ($q->getType() == '文本') continue;
            if (!array_key_exists($qid, $report_data)) {
                $report_data[$qid] = array();
                $report_data[$qid][0] = 0;
            }

            $content = $detail->getContent();
            $tmp = preg_split('/[\n]/', $content, -1, PREG_SPLIT_NO_EMPTY);
            foreach ($tmp as $val) {
                $value = trim($val);
                if (array_key_exists($value, $report_data[$qid]))
                    $report_data[$qid][$value]++;
                else
                    $report_data[$qid][$value] = 1;
                $report_data[$qid][0]++;
            }
        }
    }


    foreach ($reader_survey->getQuestions() as $question) {
        if ($question->getType() == '文本') continue;
        echo '<tr>';
        echo '<td>' . $question->getId() . '</td>';
        echo '<td>' . $question->getTitle() . '</td>';

//        $feedbacks = Doctrine_Core::getTable('ReaderSurveyFeedback')->createQuery('f')
//                ->addWhere('f.survey_id=?', $reader_survey->getId())->addWhere('f.question_id=?', $question->getId())->execute();
//
//        $result = array();
//        $count = 0;
//        foreach ($feedbacks as $feedback) {
//            $feedbackContent = $feedback->getContent();
//            $tmp = preg_split('/[\n]/', $feedbackContent, -1, PREG_SPLIT_NO_EMPTY);
//            if (is_array($tmp)) //多选
//            {
//                foreach ($tmp as $val)
//                {
//                    $value = trim($val);
//                    if (array_key_exists($value, $result)) {
//                        $result[$value]++;
//                    } else {
//                        $result[$value] = 1;
//                    }
//                    $count++;
//                }
//
//            } else
//            {
//                $value = trim($tmp);
//                if (array_key_exists($value, $result)) {
//                    $result[$value]++;
//                } else {
//                    $result[$value] = 1;
//                }
//                $count++;
//            }
//        }

        $qid = $question->getId();
        arsort(&$report_data[$qid]);
        $count = $report_data[$qid][0];
        $result = $report_data[$qid];
        echo '<td><table>';
        foreach ($result as $key => $val) {
            if (is_int($key) && $key == 0) continue;
            echo '<tr><td>' . $key . '</td><td> ' . $val . '</td> <td>' . round($val * 100 / (float)$count, 1) . '%</td></tr>';
        }
        echo '</table></td>';

        echo '</tr>';
    }
}
    ?>

</table>
 
